package com.xzx.helloworld;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/10/14 18:17
 */
public class TimerClient {
    public static void main(String[] args) {
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();

            bootstrap.group(workerGroup)
                    .channel(NioSocketChannel.class)
                    .option(ChannelOption.SO_KEEPALIVE, true)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
//                            ch.pipeline().addLast(new TimerClientHandler());
//                            ch.pipeline().addLast(new TimerClientHandlerV2());
//                            ch.pipeline().addLast(new TimeDecoder(), new TimerClientHandler());
//                            ch.pipeline().addLast(new TimeDecoderV2(), new TimerClientHandler());
                            ch.pipeline().addLast(new TimerPojoDecoder(), new TimerPojoClientHandler());
                        }
                    });


            ChannelFuture future = bootstrap.connect("127.0.0.1", 9999).sync();
            System.out.println("Client Started");
            future.channel().closeFuture().sync();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            workerGroup.shutdownGracefully();
        }
    }
}
